package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.enums.BasicEnum;
import com.zzyl.exception.BaseException;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Override
    public List<NursingLevelVo> ListAll() {

        return nursingLevelMapper.ListAll();

    }

    @Override
    public void addLevel(NursingLevelDto dto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(dto, nursingLevel);
        //TODO:创建人与修改人
        nursingLevel.setCreateBy(1671403256519078153L);
        nursingLevel.setUpdateBy(1671403256519078153L);
        nursingLevel.setCreateTime(LocalDateTime.now());
        nursingLevel.setUpdateTime(LocalDateTime.now());
        try {
            nursingLevelMapper.addLevel(nursingLevel);
        } catch (Exception e) {
            throw  new BaseException(BasicEnum.ABNORMAL_ADDITION_OF_NURSING_LEVEL);
        }
    }

    @Override
    public PageResponse<NursingLevelVo> queryPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevelVo> page = nursingLevelMapper.pageBuConditional(name, status);
        return PageResponse.of(page, NursingLevelVo.class);
    }

    @Override
    public NursingLevelVo queryById(Long id) {
        NursingLevel level = nursingLevelMapper.queryById(id);
        NursingLevelVo nursingLevelVo = new NursingLevelVo();
        BeanUtils.copyProperties(level, nursingLevelVo);
        return nursingLevelVo;
    }

    @Override
    public int updateById(NursingLevelDto dto) {
        NursingLevel level = new NursingLevel();
        BeanUtils.copyProperties(dto, level);
        return nursingLevelMapper.updateById(level);
    }

    @Override
    public int deleteById(Long id) {
        return nursingLevelMapper.deleteById(id);
    }

    @Override
    public int updateStauts(Long id, Integer status) {
        return nursingLevelMapper.updateStauts(id,status);
    }
}
